﻿using Humanizer;
using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.Equipment;
using MVC_System.DTO.Workshop;
using Newtonsoft.Json;
using NuGet.Common;
using WMS_MAV;

namespace MVC_System.Controllers
{
    /// <summary>
    /// 机床管理控制器
    /// </summary>
    public class EquipmentController : Controller
    {
        /// <summary>
        /// 服务
        /// </summary>
        private readonly IConfiguration _configuration;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="configuration">服务</param>
        public EquipmentController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult EquipmentShow()
        {
            return View();
        }
        /// <summary>
        ///机床显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> EquipmentsShow(EquipmentDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Equipments/Get?pageIndex=" + dto.pageIndex + "&pageSize=" + dto.pageSize + "&equipmentName=" + dto.equipmentName + "&equipmentNumbering=" + dto.equipmentNumbering + "&equipmentState=" + dto.equipmentState;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 机床添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> EquipmentsAdd(EquipmentAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Equipments/Add";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 机床删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> EquipmentsDelete(EquipmentDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Equipments/Deletes";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 机床批量删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> EquipmentsPiDelete(EquipmentDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Equipments/Delete";
            var list = "{\"equipmentId\":" + dto.Data + "}";
            var respomse = await client.PostAsync(url, list);
            return Json(respomse);
        }
        /// <summary>
        /// 机床反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> EquipmentsFind(EquipmentModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Equipments/GetById?equipmentId=" + dto.equipmentId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 机床修改
        /// </summary>
        /// <param name="obj1"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task<ActionResult> EquipmentsUpdate(EquipmentUpdateDTO obj1, string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url =_configuration["Url"] + "Workshop/api/Equipments/Update";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 机床修改状态
        /// </summary>
        /// <param name="obj1"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task<ActionResult> EquipmentsUpdateState(EquipmentModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Equipments/EquipmentStateUpdate?equipmentId=" + dto.equipmentId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 机床上传
        /// </summary>
        /// <param name="obj1"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task<ActionResult> EquipmentsImages(EquipmentImageDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Equipments/IFileImg";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        ///机床查看
        /// </summary>
        /// <returns></returns>
        public IActionResult EquipmentsFinds()
        {
            return View();
        }
    }
}
